﻿#region [ Modification History ]
/*
 * 06/03/2013 Denis Kholine
 *  Generated Original version of source code.
 */
#endregion

#region  [ UIUC NCSA Open Source License ]
/*****************************************************************************\
 *             University of Illinois/NCSA Open Source License
 *
 * 
 *      Copyright © 2012,2013, The Board of Trustees of the University of Illinois. All rights reserved.
 *
 *      Developed by: Rakesh Bobba, Derek Dagit, Erich Heine, Denis Kholine,
 *                    Klara Nahrstedt, David Rodgers,   William H. Sanders, Tim Yardley
 *
 *      Information Trust Institute/Coordinated Science Laboratory
 * 
 *      University of Illinois
 *      
 *      The Board of Trustees of the University of Illinois
 *      109 Coble Hall
 *      801 South Wright Street
 *      Champaign, IL 61820-6242
 *
 *      http://www.iti.illinois.edu / http://csl.illinois.edu
 * 
 *      Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
 *      associated documentation files (the “Software”), to deal with the Software without restriction, 
 *      including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 *      and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
 *      subject to the following conditions:
 *
 *      Redistributions of source code must retain the above copyright notice, this list of conditions and the
 *      following disclaimers.
 *      
 *      Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
 *      the following disclaimers in the documentation and/or other materials provided with the distribution.
 *
 *      Neither the names of Information Trust institute, Coordinated Science Laboratory, University of Illinois,
 *      The Board of Trustees of the University of Illinois nor the names of its contributors may be used to 
 *      endorse or promote products derived from this Software without specific prior written permission.
 *      
 *      THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 *      LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN
 *      NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *      WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 *      SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 *      
 \*****************************************************************************/
#endregion

#region [ Using plus External Dependencies see note below]
/*
 * C:\Projects\SIEGate.ITI.05202013\Main\Source\packages\QuickGraph.3.6.61119.7\lib\net4\QuickGraph.dll
 */
using System;
using System.Data;
using SIEGate.Core;
using SIEGate.Core.Notifications;
using SIEGate.Core.MessageBusses;
using SIEGate.Core.Configurator;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GSF.TimeSeries.Transport;
#endregion

namespace SIEGateCoreTest.Configurator
{
    /// <summary>
    /// A test class for GsfHandler
    /// </summary>
    [TestClass]
    public class GsfHandlersTests
    {
        #region [ Members]
        private DataTable dtMeasurement;
        private DataRow dtMeasurementRow;
        private DataSet dtSet;
        private String dtTable = "ActiveMeasurements";
        #endregion

        #region [ Test Initialization ]
        /// <summary>
        /// Initializa Active Measurement Table 
        /// </summary>
        public void Initialize(String signalID,String pointTag)
        {

            dtSet = new DataSet("AdapterInfo");
            /**********************************************************************/            // Populate measurement table
            dtMeasurement = new DataTable(dtTable);
            dtMeasurement.Columns.Add("ID");
            dtMeasurement.Columns.Add("SignalID");
            dtMeasurement.Columns.Add("PointTag");
            dtMeasurement.Columns.Add("Adder");
            dtMeasurement.Columns.Add("Multiplier");

            dtMeasurementRow = dtMeasurement.NewRow();
            dtMeasurementRow["ID"] = (10).ToString();
            dtMeasurementRow["SignalID"] = signalID; // Guid
            dtMeasurementRow["PointTag"] = pointTag; // "GPA_PMU_34:21";
            dtMeasurementRow["Adder"] = "UIUC\\dkholine";
            dtMeasurementRow["Multiplier"] = "0.033";

            dtMeasurement.Rows.Add(dtMeasurementRow);
            dtSet.Tables.Add(dtMeasurement);
        }
        #endregion

        #region [ Methods ]
        /// <summary>
        /// A GsfHandler ParseConnectionString test
        /// </summary>
        [TestMethod]
        [TestCategory("GsfHandler")]
        public void ParseConnectionStringTests()
        {
            string inputConnectionString = string.Empty;
            inputConnectionString = "AssemblyName=CsvAdapter.dll;AssemblyPath=C:\\Adapters";
            Dictionary<string,string> output = GsfHandler.ParseConnectionString(inputConnectionString);
            int expected = 2;
            int actual = output.Count;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        /// A GsfHandler ParseStreamIDs test
        /// </summary>
        [TestMethod]
        [TestCategory("GsfHandler")]
        public void ParseStreamIDs()
        {
            String signalID = Guid.NewGuid().ToString();
            String PointTag = "GPA_PMU_34:21";
            Initialize(signalID, PointTag);

            HashSet<Guid> output = GsfHandler.ParseStreamIDs(dtSet, signalID, dtTable);
            bool expected = true;
            bool actual = output.Contains(Guid.Parse(signalID));
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        /// A GsfHandler ParseStreamIDs test
        /// </summary>
        [TestMethod]
        [TestCategory("GsfHandler")]
        public void ParseByPointTagStreamIDs()
        {
            String signalID = Guid.NewGuid().ToString();
            String PointTag = "GPA_PMU_34:21";
            Initialize(signalID, PointTag);
            HashSet<Guid> output = GsfHandler.ParseStreamIDs(dtSet, PointTag, dtTable);
            bool expected = true;
            bool actual = (output.Count == 1);
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        /// A GsfHandler ParseStreamIDs test
        /// </summary>
        [TestMethod]
        [TestCategory("GsfHandler")]
        public void ParseEmptyGuidStreamIDs()
        {
            String signalID = Guid.Empty.ToString();
            String PointTag = "GPA_PMU_34:21";
            Initialize(signalID, PointTag);
            HashSet<Guid> output = GsfHandler.ParseStreamIDs(dtSet, signalID, dtTable);
            bool expected = true;
            bool actual = (output.Count == 1);
            Assert.AreEqual(expected, actual);
        }
        #endregion
    }
}